package com.kfm.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/getSession")
public class GetSessionServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取Session对象
        HttpSession session = req.getSession();
        System.out.println(session);
        // 获取Session对象存储的共享数据 getAttribute(key)
        Object value = session.getAttribute("name");
        System.out.println(value);
        session.invalidate();
        // 删除存储在Session中的指定数据
        session.removeAttribute("name");
        System.out.println("删除存储的name");

        System.out.println(session.getAttribute("name"));
    }
}
